package pl.put.miasi.volleyball;


import org.jbox2d.collision.PolygonDef;
import org.jbox2d.dynamics.Body;
import org.jbox2d.dynamics.BodyDef;
import org.jbox2d.dynamics.World;

public class B2Walls {

	private World world;
	private Main main;
	private Volleyball volleyball;
	
	//upper part of net column
	protected Body netEndingPart = null;
	BodyDef wallBodyDef;
	PolygonDef wall;
	Body wallBody;
	
	public B2Walls(Volleyball volleyball) {
		this.volleyball = volleyball;
		this.world =  this.volleyball.m_world;
		this.main = this.volleyball.parent;
	}
		
	public Body getNetEndingPart() {
		return netEndingPart;
	}
	
	public void initialize() {
		/*
		 * Create Walls
		 */
		
		wallBodyDef = new BodyDef();
		wallBodyDef.userData = "wall";
		wallBodyDef.position.set(Settings.lWallPos);
		wallBody = world.createStaticBody(wallBodyDef);
		wall = new PolygonDef();
		wall.density = 0.0f;
		wall.restitution = Settings.WALL_RESTITUTION;
		wall.setAsBox(Settings.lWallHX, Settings.lWallHY);
		wallBody.createShape(wall);

		wallBodyDef = new BodyDef();
		wallBodyDef.userData = "wall";
		wallBodyDef.position.set(Settings.rWallPos);
		wallBody = world.createStaticBody(wallBodyDef);
		wall = new PolygonDef();
		wall.density = 0.0f;
		wall.restitution = Settings.WALL_RESTITUTION;
		wall.setAsBox(Settings.rWallHX, Settings.rWallHY);
		wallBody.createShape(wall);

		
		wallBodyDef = new BodyDef();
		wallBodyDef.userData = "wall";
		wallBodyDef.position.set(Settings.ceilingPos);
		wallBody = world.createStaticBody(wallBodyDef);
		wall = new PolygonDef();
		wall.density = 0.0f;
		wall.restitution = Settings.WALL_RESTITUTION;
		wall.setAsBox(Settings.ceilingHX, Settings.ceilingHY);
		wallBody.createShape(wall);
		
		wallBodyDef = new BodyDef();
		wallBodyDef.userData = "wall";
		wallBodyDef.position.set(Settings.lowerNetPos);
		wallBody = world.createStaticBody(wallBodyDef);
		wall = new PolygonDef();
		wall.density = 0.0f;
		wall.restitution = Settings.WALL_RESTITUTION;
		wall.setAsBox(Settings.lowerNetHX, Settings.lowerNetHY);
		wallBody.createShape(wall);
			
		netEndingPart = wallBody;

		/*
		 * Create ground
		 */
		BodyDef groundBodyDef = new BodyDef();
		groundBodyDef.userData = "ground";
		groundBodyDef.position.set(Settings.groundPos);
		Body groundBody = world.createStaticBody(groundBodyDef);
		PolygonDef groundShape = new PolygonDef();
		groundShape.density = 0.0f;
		groundShape.restitution = Settings.WALL_RESTITUTION;
		groundShape.setAsBox(Settings.groundHX, Settings.groundHY);
		groundBody.createShape(groundShape);

	}

}
